import { lazy, Suspense } from "react";
import { Navigate } from "react-router-dom";

const Home = lazy(() => import("@/pages/home"));
const Game = lazy(() => import("@/pages/game"));
const GameList = lazy(() => import("@/pages/game/gameList"));
const GameInfo = lazy(() => import("@/pages/game/gameInfo"));
const Community = lazy(() => import("@/pages/community"));

const PostInfo = lazy(() => import("@/pages/community/postInfo"));
const PostList = lazy(() => import("@/pages/community/postList"));

const Me = lazy(() => import("@/pages/me"));
const Userinfo = lazy(() => import("@/pages/userinfo"));

const ShopCar = lazy(() => import("@/pages/shop/index"));

const Warehouse = lazy(() => import("@/pages/warehouse/index"));

const mainRoutes = [
  {
    index: true,
    element: <Navigate to="/home" replace />,
    meta: {
      isShowNav: false,
    },
  },
  {
    path: "/home",
    element: (
      <Suspense>
        <Home />
      </Suspense>
    ),
    meta: {
      title: "首页",
      isShowNav: true,
      requiresAuth: false,
    },
  },
  {
    path: "/game",
    element: (
      <Suspense>
        <Game />
      </Suspense>
    ),
    meta: {
      title: "游戏",
      isShowNav: true,
      requiresAuth: true,
    },
    children: [
      {
        index: true,
        element: (
          <Suspense>
            <GameList />
          </Suspense>
        ),
        meta: {
          title: "游戏列表",
          requiresAuth: true,
        },
      },
      {
        path: "game_info/:id",
        element: (
          <Suspense>
            <GameInfo />
          </Suspense>
        ),
        meta: {
          title: "游戏详情",
          requiresAuth: true,
        },
      },
    ],
  },
  {
    path: "community",
    element: (
      <Suspense>
        <Community />
      </Suspense>
    ),
    meta: {
      title: "社区",
      isShowNav: true,
      requiresAuth: true,
    },
    children: [
      {
        index: true,
        element: (
          <Suspense>
            <PostList />
          </Suspense>
        ),
        meta: {
          title: "帖子列表",
          requiresAuth: true,
        },
      },
      {
        path: "post_info/:id",
        element: (
          <Suspense>
            <PostInfo />
          </Suspense>
        ),
        meta: {
          title: "帖子详情",
          requiresAuth: true,
        },
      },
    ],
  },
  {
    path: "/me",
    element: (
      <Suspense>
        <Me />
      </Suspense>
    ),
    meta: {
      title: "我的",
      isShowNav: true,
      requiresAuth: true,
    },
  },
  {
    path: "/userinfo",
    element: (
      <Suspense>
        <Userinfo />
      </Suspense>
    ),
    meta: {
      title: "个人信息",
      isShowNav: false,
      requiresAuth: true,
    },
    children: [],
  },
  {
    path: "/shopcar",
    element: (
      <Suspense>
        <ShopCar />
      </Suspense>
    ),
    meta: {
      title: "购物车",
      isShowNav: false,
      requiresAuth: true,
    },
  },
  {
    path: "/warehouse",
    element: (
      <Suspense>
        <Warehouse />
      </Suspense>
    ),
    meta: {
      title: "游戏仓库",
      isShowNav: false,
      requiresAuth: true,
    },
  },
];

export default mainRoutes;
